<?php

include("classes/include.php");

session_start();


//echo "pwet1".isset($_POST['fent']) ."pwet2". isset($_POST['fle1ad1'])
//		."pwet3". isset($_POST['fle1codepostal']) ."pwet4". isset($_POST['fle1ville'])
//		."pwet5". isset($_POST['flemail']) ."pwet6". isset($_POST['fltel'])
//		."pwet7". isset($_POST['flnomresp']) ."pwet8". isset($_POST['flpresp'])
//		."pwet9". isset($_POST['fleresp']) ."pwet10". isset($_POST['fltelresp'])
//		."pwet11". isset($_POST['fldds']) ."pwet12". isset($_POST['fldfs'])
//		."pwet13". isset($_POST['flsujets']);

if(isset($_POST['fent']) && isset($_POST['fle1ad1'])
		&& isset($_POST['fle1codepostal']) && isset($_POST['fle1ville'])
		&& isset($_POST['flemail']) && isset($_POST['fltel'])
		&& isset($_POST['fnomresp']) && isset($_POST['flpresp'])
		&& isset($_POST['fleresp']) && isset($_POST['fltelresp'])
		&& isset($_POST['fldds']) && isset($_POST['fldfs'])
		&& isset($_POST['flsujets']))
		{
			
			$nomE = $_POST['fent'];
			$addE = $_POST['fle1ad1'];
			if(isset($_POST['fle1ad2']))
				$addE = $addE." ".$_POST['fle1ad2'];
				
			$addE = $addE." ".$_POST['fle1codepostal']." ".$_POST['fle1ville'];
			$telE = $_POST['fltel'];
			$mailE = $_POST['flemail']; 
			
			$ent = new Entreprise(-1, $nomE, $addE, $mailE, $telE);
			$ent->ajouter();
			
			
			$nomR = $_POST['fnomresp'];
			$prenomR = $_POST['flpresp'];
			$mailR = $_POST['fleresp'];
			$telR = $_POST['fltelresp'];
			
			$resp = new ResponsableEntreprise(-1, $nomR, $prenomR, $telR, $mailR, $ent);
			$resp->ajouter();
			
			$dateDeb = $_POST['fldds'];
			$dateFin = $_POST['fldfs'];
			$sujet = $_POST['flsujets'];
			
			$req = new RequeteSQL("INSERT INTO stage VALUES('',
													".$_SESSION['utilisateur']->getNumUtilisateur().",
													".$ent->getNumEntreprise().",
													".$resp->getNumResp().",
													'".$sujet."',
													'',
													'',
													'',
													str_to_date('".$dateDeb."','%d/%m/%Y'),
													str_to_date('".$dateFin."','%d/%m/%Y'))");
			
			$req->executeEcriture();
			
			header("Location: enregistrerSujet.php");
		}
?>